import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

public class ShowService implements Loggable {
    private List<Show> showList = new ArrayList<>();
    private int showIdCounter = 1;

    public void autoArrangeShows(List<Movie> movies, List<Hall> halls) {
        LocalDateTime baseTime = LocalDateTime.now().plusHours(1); // 从1小时后开始排片
        
        for (Movie movie : movies) {
            for (Hall hall : halls) {
                // 每天排3场：10:00、15:00、19:00
                for (int hour : new int[]{10, 15, 19}) {
                    LocalDateTime showTime = baseTime.withHour(hour).withMinute(0);
                    // 高分影片票价更高
                    double price = movie.getScore() > 8.0 ? 60.0 : 45.0;
                    
                    Show show = new Show(
                        "S" + String.format("%03d", showIdCounter++),
                        movie,
                        hall,
                        showTime,
                        price
                    );
                    showList.add(show);
                }
            }
        }
        // 初始化时不记录日志（无登录用户）
        System.out.println("自动排片完成，共" + showList.size() + "场");
    }

    public List<Show> getAllShows() {
        return showList;
    }
}